package zhr.chapter8;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Example8_11 {
    public static void main(String[] args) {
        HashMap<Integer, String> hashMap1 = new HashMap<>();
        hashMap1.put(97, "abc79");
        hashMap1.put(123, "abc123");
        hashMap1.put(22, "abc22");
        hashMap1.put(4, "abc4");
        hashMap1.put(69, "abc69");
        hashMap1.remove(69);
        hashMap1.put(100, "xyz100");
        System.out.println(hashMap1.get(100));

        show(hashMap1.keySet());
        show(hashMap1.values());
        show(hashMap1.entrySet());
        showMap(hashMap1);
        System.out.println();
    }

    public static void show(Collection collection) {
        Iterator it = collection.iterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();
    }

    public static void showMap(Map map) {
        Iterator it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            System.out.println("Key is " + entry.getKey() + ",Value is " + entry.getValue());
        }
        System.out.println();
    }
}
